import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { DiningRestaurantApi } from '#/api/spa/dining/restaurant';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'groupId',
      label: '集团ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入集团ID',
      },
    },
    {
      fieldName: 'storeId',
      label: '所属门店ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入所属门店ID',
      },
    },
    {
      fieldName: 'restaurantCode',
      label: '餐厅编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入餐厅编码',
      },
    },
    {
      fieldName: 'restaurantName',
      label: '餐厅名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入餐厅名称',
      },
    },
    {
      fieldName: 'restaurantType',
      label: '餐厅类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择餐厅类型',
      },
    },
    {
      fieldName: 'floorNumber',
      label: '所在楼层',
      component: 'Input',
      componentProps: {
        placeholder: '请输入所在楼层',
      },
    },
    {
      fieldName: 'areaName',
      label: '所属区域名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入所属区域名称',
      },
    },
    {
      fieldName: 'description',
      label: '餐厅描述',
      component: 'RichTextarea',
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'groupId',
      label: '集团ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入集团ID',
      },
    },
    {
      fieldName: 'storeId',
      label: '所属门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入所属门店ID',
      },
    },
    {
      fieldName: 'restaurantCode',
      label: '餐厅编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入餐厅编码',
      },
    },
    {
      fieldName: 'restaurantName',
      label: '餐厅名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入餐厅名称',
      },
    },
    {
      fieldName: 'restaurantType',
      label: '餐厅类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择餐厅类型',
      },
    },
    {
      fieldName: 'floorNumber',
      label: '所在楼层',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入所在楼层',
      },
    },
    {
      fieldName: 'areaName',
      label: '所属区域名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入所属区域名称',
      },
    },
    {
      fieldName: 'description',
      label: '餐厅描述',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入餐厅描述',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<DiningRestaurantApi.DiningRestaurant>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'groupId',
      title: '集团ID',
      minWidth: 120,
    },
    {
      field: 'storeId',
      title: '所属门店ID',
      minWidth: 120,
    },
    {
      field: 'restaurantCode',
      title: '餐厅编码',
      minWidth: 120,
    },
    {
      field: 'restaurantName',
      title: '餐厅名称',
      minWidth: 120,
    },
    {
      field: 'restaurantType',
      title: '餐厅类型',
      minWidth: 120,
    },
    {
      field: 'floorNumber',
      title: '所在楼层',
      minWidth: 120,
    },
    {
      field: 'areaName',
      title: '所属区域名称',
      minWidth: 120,
    },
    {
      field: 'description',
      title: '餐厅描述',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
